export default {
  props: {},
  data () {
    return {}
  },
  computed: {},
  created () {
  },
  methods: {
    // 复制
    copyInfo (row, type) {
      // console.log(row, 'row')
      const that = this
      let info
      let str
      switch (type) {
        case 'service':
          str = '跟进客服名称'
          info = (row.applierName == null ? '无' : row.applierName)
          break
        case 'express':
          str = '复制物流单号'
          info = (row.logisticsNumber == null ? '无' : row.logisticsNumber)
          break
        case 'afterOrder':
          str = '售后编号'
          info = (row.afterNo == null ? '无' : row.afterNo)
          break
        default: // 复制 orderNo
          str = '订单编号'
          info = (row.orderNo == null ? '无' : row.orderNo)
      }
      that.$copyText(info).then(
        function (e) {
          that.$message({
            type: 'success',
            message: `复制【${str}】成功`
          })
        },
        function (e) {
          that.$message({
            type: 'warning',
            message: '复制失败'
          })
        }
      )
    },
    // 关闭订单确定
    handlerCloseOrderSubmit () {
      const data = {
        // id: Number(this.cancelOrderId),
        id: this.cancelOrderId,
        closeReason: this.setCloseOrder
      }
      this.$api.closeOrder(data).then(res => {
        if (res.code == 0) {
          this.$message.success('操作成功')
          this.dialog.visible = false
          this.fetchData('search')
        }
      })
    },
    // 关闭订单 - 待提交
    cancelOrderWait (row) {
      this.$confirm('此操作将关闭订单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const params = { id: row.orderId }
        this.$api.closeOrder(params).then(res => {
          if (res.code === 0) {
            this.$parent.fetchData('search')
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        })
      })
    },
    // 重新提交订单
    onResubmitOrder (id) {
      this.$confirm('此操作将重新提交订单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const params = { id }
        this.$api.resubmitOrder(params).then((res) => {
          if (res.code === 0) {
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
            this.$parent.fetchData('search')
          }
        }).catch((err) => {
          console.log(err)
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },
    // 确认收货
    onConfirmReceipt (row) {
      console.log(row, 'row')
      this.$confirm('是否确认收货？请确认商品已签收?', '确认收货', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const params = { id: row.orderId }
        this.$api.confirmReceipt(params).then((res) => {
          if (res.code == 0) {
            this.$parent.fetchData('search', true)
            this.$message.success('操作成功')
          }
        }).catch((err) => {
          console.log(err)
        })
        console.log('确认收货成功', row)
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消收货'
        })
        console.log('已取消收货', row)
      })
    },
    resTableShowDialog (obj) {
      const { title, width, type, data, batch } = obj
      this.showDialog(title, width, type, data, batch)
    },
    // 关闭订单打开弹框
    onCancelOrderMsg (row) {
      this.setCloseOrder = ''
      this.dialog.visible = true
      this.dialog.title = '取消订单'
      this.dialog.width = '540px'
      this.dialog.type = 'closeOrder'
      this.cancelOrderId = row.orderId
    }
  }
}
